package basic;

import org.bee.tl.ext.jfinal.BeetlRenderFactory;

import reservation.ReservationController;
import room.RoomController;

import test.ExcelController;
import user.UserController;

import model.Bussiness;
import model.Customer;
import model.Reservation;
import model.Room;
import model.Roomtype;
import model.UserInfo;
import model.Vip;

import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

//基础类
public class BasicConfig extends JFinalConfig {

	public void configConstant(Constants me) {
		//me.setViewType(ViewType.FREE_MARKER);//设置freemaker视图
		loadPropertyFile("config.txt");
		me.setMainRenderFactory(new BeetlRenderFactory());//使用beetl
		me.setDevMode(getPropertyToBoolean("devMode", false));
	}

	public void configHandler(Handlers me) {
		me.add(new AllHandler(".*\\.html"));
	}

	public void configInterceptor(Interceptors me) {
		me.add(new SessionInViewInterceptor());//能关联beetl输出的session
	}

	public void configPlugin(Plugins me) {
		//连接池
		//C3p0Plugin cp=new C3p0Plugin("jdbc:sqlserver://localhost:1434;databasename=demo", "sa", "sa","com.microsoft.sqlserver.jdbc.SQLServerDriver");
		C3p0Plugin cp=new C3p0Plugin(getProperty("jdbc"), 
				getProperty("user"), getProperty("password"),getProperty("driverClass"));
		me.add(cp);
		ActiveRecordPlugin arp=new ActiveRecordPlugin(cp);
		arp.setDialect(new MysqlDialect());
		me.add(arp);
		arp.addMapping("userinfo","ID", UserInfo.class);
		arp.addMapping("room","roomID", Room.class);
		arp.addMapping("roomtype","roomtype",Roomtype.class);
		arp.addMapping("bussiness","bussinessID", Bussiness.class);
		arp.addMapping("customer","customerID", Customer.class);
		arp.addMapping("vip","starLv", Vip.class);
		arp.addMapping("reservation","reservationID", Reservation.class);
	}

	public void configRoute(Routes me) {
		//设置路径拦截控制器
		me.add("excel",ExcelController.class);
		
		me.add("hello",HelloController.class);
		me.add("login",UserController.class);
		me.add("reservation",ReservationController.class);
		me.add("room",RoomController.class);
		me.add("/",IndexController.class);
		
		
	}

	
}
